package com.huluobo.higt4demo1911.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.huluobo.higt4demo1911.R;
import com.huluobo.higt4demo1911.bean.VideoBean;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Created by lc on 2022/4/27.
 */
public class VideoFullScreenAdapter extends BaseQuickAdapter<VideoBean, BaseViewHolder> {
    public VideoFullScreenAdapter(@Nullable List<VideoBean> data) {
        super(R.layout.item_full_screen_video, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, VideoBean videoBean) {
        StandardGSYVideoPlayer videoPlayer = baseViewHolder.getView(R.id.item_full_screen_video_player);
        videoPlayer.setUp(videoBean.videopath, true, "");
        videoPlayer.setThumbImageView(getThumbView(videoBean.videomainimg));
        videoPlayer.getBackButton().setVisibility(View.GONE);
    }

    //构建封面层
    private ImageView getThumbView(String url) {
        ImageView imageView = new ImageView(getContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        RelativeLayout.LayoutParams params =
                new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(params);
        Glide.with(getContext()).load(url)
                .error(R.mipmap.ic_launcher)
                .placeholder(R.mipmap.ic_launcher).into(imageView);
        return imageView;
    }
}
